package com.feicheng.lanniao.service.impl;
import com.feicheng.lanniao.entity.Person;
import com.feicheng.lanniao.mapper.PersonMapper;
import com.feicheng.lanniao.result.ResultInfo;
import com.feicheng.lanniao.service.IPersonService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author feichengTech
 * @since 2021-09-02
 */
@Service
public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person> implements IPersonService {
	@Autowired
	PersonMapper PersonMapper;
	/**
	 * @see IPersonService.addPersonInfo
	 */
	@Override
	public ResultInfo addPersonInfo(Person person) {
		//如果返回值为1则返回success
		if(PersonMapper.insert(person) > 0 ) {
			return ResultInfo.success();
		} else {
			//否则返回error
			return ResultInfo.error("添加有误");
		}
	}
	
	/**
	 * @see IPersonService.updatPersonInfo
	 */
	@Override
	public ResultInfo updatPersonInfo(Person person) {
		QueryWrapper<Person> qWrapper = new QueryWrapper<Person>();
		//根据id查询
		qWrapper.eq("person_id",person.getPersonId());
		//id相同修改
		if(null != person.getPersonId()) {
			} 
		this.update(person,qWrapper);
		return ResultInfo.success();
		}
	
	/**
	 * @see IPersonService.selectOneInfo
	 */
	@Override
	public ResultInfo selectOneInfo(Integer personId) {
		QueryWrapper<Person> qWrapper = new QueryWrapper<Person>();
		//查找相同id
		qWrapper.eq("person_id",personId);
		PersonMapper.selectOne(qWrapper);
		return ResultInfo.success();
	}
}
